<?php 
	
$agentID = $_GET['visa'];
$cusID   = $_GET['cus'];
if(wp_verify_nonce($_POST['act_update_visa'],'act_update_visa'))
{	

	//print_r($_POST);
	## update customer
	$params = array();
	$params['name'] = $_POST['update_customerName'];
	$params['address'] = $_POST['update_customerAddress'];
	$params['email'] = $_POST['update_customerEmail'];
	$params['tel'] = $_POST['update_customerTel'];
	$params['fax'] = $_POST['update_customerFax'];
	
	$customerID = $_POST['update_customerID'];				
	db_update_customer($customerID,$params);
	
	## update Guest
	for($t=1;$t<=5;$t++)
	{
		$name = $_POST['update_customerName'.$t];
		$pass = $_POST['update_customerpassport'.$t];
		$guestid = $_POST['update_customerguest'.$t];
		if($name && $pass)
		{
			db_update_guest($name,$pass,$guestid);
		}
	}
	## update visa	
	db_update_visa($_POST,$agentID);
	
	$paystatus = $_POST['update_payment_status'];
	$payid     = $_POST['update_paymentID'];
	db_update_payment_status($paystatus,$payid);
	
}

$customers = db_select_data_by_int("customers", "ID", $cusID);
$visas = db_select_data_by_int("visas", "ID", $agentID);

?>
<form action="" method="post">
<div class="view-booking-detail">
	<h1>Agent Company Infomation</h1>
	<table>
		<tr>
			<td class="booked-title">Number Of Visa</td>
			<td class="booked-item"><span>
			<select name="update_numberVisa">
                <?php db_get_number_of_visa($visas[0]->numberVisa);?>
            </select>
			
			<input type="hidden" name="update_customerID" value="<?php echo $cusID;?>">
			</span></td>
			
			<td class="booked-title">Type Of Visa</td>
			<td class="booked-item"><span>
			<select name="update_typeVisa">
                  <?php db_get_type_of_visa($visas[0]->typeVisa);?>
            </select>
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Purpose of visit</td>
			<td class="booked-item"><span>
			<select name="update_purpose">
                 <?php db_purpose_of_visit($visas[0]->purposeVisa);?>
           </select>
			</span></td>
			
			<td class="booked-title">Processing time</td>
			<td class="booked-item"><span>
			<select name="update_processing">
                 <?php db_processing_time($visas[0]->processingTime);?>
           </select>
			
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Date arrival</td>
			<td class="booked-item"><span>
			
			<?php
                            	
                            		 			$originalDate =$visas[0]->dateArrival; //date('Y-m-d h:i:s');   
                            		 			//print_r($originalDate);                                               
                                                $newDate_IY = date("Y", strtotime($originalDate));
                                                $newDate_IM = date("m", strtotime($originalDate));
                                                $newDate_ID = date("d", strtotime($originalDate));
                            	
                                                                                    
                                            ?>
                                            <?php
                                            $date = date('Y');
                                            ?>
                                <select name="update_dy_date_arrival" id="update_dy_date_arrival">
                                	<?php
                    							for($i = 1;$i<=30;$i++)
                    							{
                    								if($i == $newDate_ID)
                    								{
                    								?>
                    									<option selected="selected" value="<?php echo $i;?>"><?php echo $i;?></option>
                    								<?php	
                    								}
                    								else 
                    								{
                    							?>
                    								<option value="<?php echo $i;?>"><?php echo $i;?></option>
                    							<?php
                    								} 								
                    							}	 
                    							?>	
                                </select>
                                <select name="update_mo_date_arrival" id="update_mo_date_arrival">
                                	<option <?php if($newDate_IM == 1) echo 'selected="selected"';?> value="01">January </option>
                                                <option <?php if($newDate_IM == 2) echo 'selected="selected"';?> value="02">February </option>
                                                <option <?php if($newDate_IM == 3) echo 'selected="selected"';?> value="03">March </option>
                                                <option <?php if($newDate_IM == 4) echo 'selected="selected"';?> value="04">April </option>
                                                <option <?php if($newDate_IM == 5) echo 'selected="selected"';?> value="05">May </option>
                                                <option <?php if($newDate_IM == 6) echo 'selected="selected"';?> value="06">June </option>
                                                <option <?php if($newDate_IM == 7) echo 'selected="selected"';?> value="07">July </option>
                                                <option <?php if($newDate_IM == 8) echo 'selected="selected"';?> value="08">August </option>
                                                <option <?php if($newDate_IM == 9) echo 'selected="selected"';?> value="09">September </option>
                                                <option <?php if($newDate_IM == 10) echo 'selected="selected"';?> value="10">October </option>
                                                <option <?php if($newDate_IM == 11) echo 'selected="selected"';?> value="11">November </option>
                                                <option <?php if($newDate_IM == 12) echo 'selected="selected"';?> value="12">December </option>
                                </select>
                                <select name="update_yr_date_arrival" id="update_yr_date_arrival">
                                	<?php                    								
                    								for($y = $date; $y <= $date+5 ; $y++)
                    								{
                    									if($y == $newDate_IY)
                    									{
                    									?>
                    										<option selected="selected" value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 										
                    									}
                    									else 
                    									{
                    									?>
                    										<option value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 	
                    									}					
                    								}				
                    							?>
                                </select>
			
			</span></td>
			
			<td class="booked-title">Date of exit</td>
			<td class="booked-item"><span>
			
			 <?php
			 					
                            	
                            		 			$originalDate =$visas[0]->dateExit; //date('Y-m-d h:i:s');    
                            		 			                                          
                                                $newDate_IY = date("Y", strtotime($originalDate));
                                                $newDate_IM = date("m", strtotime($originalDate));
                                                $newDate_ID = date("d", strtotime($originalDate));
                            	                                                                               
                                            ?>
                                            <?php
                                            $date = date('Y');
                                            ?>
                                <select name="update_dy_date_exit" id="update_dy_date_exit">
                                	<?php
                    							for($i = 1;$i<=30;$i++)
                    							{
                    								if($i == $newDate_ID)
                    								{
                    								?>
                    									<option selected="selected" value="<?php echo $i;?>"><?php echo $i;?></option>
                    								<?php	
                    								}
                    								else 
                    								{
                    							?>
                    								<option value="<?php echo $i;?>"><?php echo $i;?></option>
                    							<?php
                    								} 								
                    							}	 
                    							?>	
                                </select>
                                <select name="update_mo_date_exit" id="update_mo_date_exit">
                                	<option <?php if($newDate_IM == 1) echo 'selected="selected"';?> value="01">January </option>
                                                <option <?php if($newDate_IM == 2) echo 'selected="selected"';?> value="02">February </option>
                                                <option <?php if($newDate_IM == 3) echo 'selected="selected"';?> value="03">March </option>
                                                <option <?php if($newDate_IM == 4) echo 'selected="selected"';?> value="04">April </option>
                                                <option <?php if($newDate_IM == 5) echo 'selected="selected"';?> value="05">May </option>
                                                <option <?php if($newDate_IM == 6) echo 'selected="selected"';?> value="06">June </option>
                                                <option <?php if($newDate_IM == 7) echo 'selected="selected"';?> value="07">July </option>
                                                <option <?php if($newDate_IM == 8) echo 'selected="selected"';?> value="08">August </option>
                                                <option <?php if($newDate_IM == 9) echo 'selected="selected"';?> value="09">September </option>
                                                <option <?php if($newDate_IM == 10) echo 'selected="selected"';?> value="10">October </option>
                                                <option <?php if($newDate_IM == 11) echo 'selected="selected"';?> value="11">November </option>
                                                <option <?php if($newDate_IM == 12) echo 'selected="selected"';?> value="12">December </option>
                                </select>
                                <select name="update_yr_date_exit" id="update_yr_date_exit">
                                	<?php                    								
                    								for($y = $date; $y <= $date+5 ; $y++)
                    								{
                    									if($y == $newDate_IY)
                    									{
                    									?>
                    										<option selected="selected" value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 										
                    									}
                    									else 
                    									{
                    									?>
                    										<option value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 	
                    									}					
                    								}				
                    							?>
                                </select>
			
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Arrival aiport </td>
			<td class="booked-item"><span>
			<select name="update_arrivalAirport">
                 <?php db_get_arrival_airport($visas[0]->arrivalAirport);?>
             </select>
			</span></td>
			
			<td class="booked-title">Flight number</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_flight_number" value="<?php echo $visas[0]->flightNumber;?>">
			</span></td>
		</tr>
		<tr>
			<td class="booked-title">Payment Status</td>
			<td class="booked-item"><span>
			<?php
			$list_payment = db_select_data_by_int("payments", "ID", $visas[0]->paymentID); 
			$lists = db_get_list_payment_status();
			?>
			<select name="update_payment_status">
                 <?php
                 foreach ($lists as $value) 
                 {
                 	if($value == $list_payment[0]->paymentStatus)
                 		echo '<option selected="selected" value="'.$value.'">'.$value.'</option>';
                 	else 
                 		echo '<option value="'.$value.'">'.$value.'</option>';
                 } 
                 ?>
             </select>
             <input type="hidden" name="update_paymentID" value="<?php echo $visas[0]->paymentID;?>">
			</span></td>
			
			<td class="booked-title"></td>
			<td class="booked-item"><span>
			
			</span></td>
		</tr>
				
		<!-- ********************************************************************** -->
		<?php 
			$list_gues = db_select_data_by_int("customers", "guestParent", $cusID); 
			if($list_gues)
			{
		?>
		<tr>
			<td class="booked-title" colspan="4"><h2>Guest Infomation</h2></td>
			
		</tr>
		<?php
				$j=1;
				foreach ($list_gues as $value) 
				{
					$id = $value->ID;
					$passport = db_select_data_by_int("passports", "customerID", $id);
				?>
				<tr>
					<td class="booked-title">Guest Name</td>
					<td class="booked-item"><span>
					<input type="text" class="select_size" name="update_customerName<?php echo $j;?>" value="<?php echo $value->customerName;?>">
					<input type="hidden" class="select_size" name="update_customerguest<?php echo $j;?>" value="<?php echo $value->ID;?>">
					</span></td>
					
					<td class="booked-title">Passport</td>
					<td class="booked-item"><span>
					<input type="text" class="select_size" name="update_customerpassport<?php echo $j;?>" value="<?php echo $passport->passportNumber;?>">
					</span></td>
				</tr>
				<?php 
				$j++;	
				} 		
			} 
		?>
		<tr>
			<td class="booked-title" colspan="4"><h2>Customer Infomation</h2></td>
			
		</tr>
		<tr>
			<td class="booked-title">Customer Name</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerName" value="<?php echo $customers[0]->customerName;?>">
			</span></td>
			
			<td class="booked-title">Customer Address</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerAddress" value="<?php echo $customers[0]->customerAddress;?>">
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Customer Email</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerEmail" value="<?php echo $customers[0]->customerEmail;?>">
			</span></td>
			
			<td class="booked-title">Customer Phone</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerTel" value="<?php echo $customers[0]->customerPhone;?>">
			</span></td>
		</tr>
		<!-- 
		<tr>
			<td class="booked-title">Customer Fax</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerFax" value="<?php echo $customers[0]->customerFax;?>">
			</span></td>
		</tr>
		 -->
		<tr>
			<td class="booked-title">Customer Comment</td>
			<td class="booked-item"><span><?php echo $customers[0]->customerComment;?></span></td>
		</tr>		
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item">
				<input type="submit" name="update_now_tour" value="Update Now">
				<a href="<?php bloginfo('home');?>/wp-admin/admin.php?page=travel-visa-setting">Return</a>
			</td>
		</tr>
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item"></td>
		</tr>
	</table>		
</div>
<?php wp_nonce_field('act_update_visa','act_update_visa');?>
</form>